# coding=utf-8

from . import base
from .component import Component


## 实现一个组件，需要写如下几个方法：
class Paperless(Component):

    ## 依赖的组件，返回类型为 string 数组，例如 return ["docker"]，表示该组件依赖的其他组件
    def dependencies(self):
        if base.is_windows():
            return []
        else:
            return ["mqtt_server"]



    ## 检测安装状态，返回true或者false，用于显示是否已经安装该组件
    def check(self):
        if base.is_windows():
            return base.check_service("gonsin_dataserver");
        else:
            return base.check_docker_container("gonsin_dataserver");



    ## 检测运行状态，返回true或者false，表示该组件是否正在运行
    def status(self):
        if base.is_windows():
            return base.is_service_running("gonsin_dataserver");
        else:
            return base.is_container_running("gonsin_dataserver");




    ## 安装组件 
    def install(self, rVersion : str = None):
        EN_PATH = base.get_env("EN_PATH")
        if base.is_windows():
            base.cmd_in_dir(f"{EN_PATH}/windows/gonsin/paperless", "install_paperless.bat")
        else:
            base.cmd_in_dir(f"{EN_PATH}/linux/gonsin/paperless", "./install_paperless.sh")
        return True;


    ## 更新组件
    def update(self, rVersion : str = None):

        ## 因为install 和 update内容相同，所以直接调用
        self.install();


    ## 卸载
    def uninstall(self):
        EN_PATH = base.get_env("EN_PATH")
        if base.is_windows():
            base.cmd_in_dir(f"{EN_PATH}/windows/gonsin/paperless", "./uninstall_paperless.bat")
        else:
            base.cmd_in_dir(f"{EN_PATH}/linux/gonsin/paperless", "./uninstall_paperless.sh")
